import logging
from flask import Flask,request,jsonify
from flasgger import Swagger
from flask_socketio import SocketIO, emit

from action.info_action import app as info_httpd
from action.task_action import app as task_httpd
from action.device_action import app as device_httd

import action.ws as ws

import threading

_thread :threading.Thread = None

def init():
    '''初始化http服务器'''
    app = Flask(__name__, static_folder='../static')

    app.register_blueprint(info_httpd)
    app.register_blueprint(task_httpd)
    app.register_blueprint(device_httd)

    swagger = Swagger(app)
    socketio = ws.init(app)

    _thread = threading.Thread(target=lambda socketio,app :socketio.run(app,debug=False),args=(socketio,app))
    _thread.setDaemon(True)
    _thread.start()
    logging.info("http服务初始化")